//      libsvm_main.cc
//      
//      Copyright 2012 tqlong <tqlong@espada>
//      
//      This program is free software; you can redistribute it and/or modify
//      it under the terms of the GNU General Public License as published by
//      the Free Software Foundation; either version 2 of the License, or
//      (at your option) any later version.
//      
//      This program is distributed in the hope that it will be useful,
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//      GNU General Public License for more details.
//      
//      You should have received a copy of the GNU General Public License
//      along with this program; if not, write to the Free Software
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//      MA 02110-1301, USA.

#ifndef LIB_SVM_WRAPPER_H
#define LIB_SVM_WRAPPER_H

#include "helper/stl_helper.h"
#include "helper/ublas_helper.h"
#include "helper/ml_data.h"

#include "svm.h"

template<typename DataTable>
void libsvm_convert_data_table(struct svm_problem& prob, DataTable& D) 
{
  const vec_t& label = D.label();
  //const typename DataTable::data_t& d = D.data();
  prob.l = sz(label);
  prob.y = new double[prob.l];
  prob.x = new svm_node*[prob.l];

  for (int i = 0; i < prob.l; i++) {
    const typename DataTable::x_t x_i = D.x(i);
    prob.y[i] = label(i);
    prob.x[i] = new svm_node[x_i.nnz()+1];
    int j = 0;
    tr(x_i, it) {
      prob.x[i][j].index = it.index();
      prob.x[i][j].value = *it;
      ++j;
    }
    prob.x[i][j].index = -1;
  }
}

#endif
